package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.member.model.Member;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 会员证转让记录
 * @author xuechao
 *
 */
@Entity
@Indexed
@Table(name = "travel_certificatestransfer")
public class CertificatesTransfer extends BaseModel{

	private static final long serialVersionUID = -9044927661588469656L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	@In
	private Long pkCertificatesTransfer;
	
	/** 合同签约 */
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkTravelContract")
	@IndexedEmbedded(depth = 1)
	private TravelContract travelContract;
	
	/** 转让人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "assignor")
	@IndexedEmbedded(depth = 1)
	private Member assignor;
	
	
	/** 接收人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "receiver")
	@IndexedEmbedded(depth = 1)
	private Member receiver;
	
	
	/** 转让类型  */
	@Enumerated(EnumType.STRING)
	@In	
	@FieldBridge(impl = EnumBridge.class)
	private TransferType transferType;
	
	/** 工本费 */
	@Field
	@Column
	private Double workCost;
	
	
	/** 经办人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "operator")
	@IndexedEmbedded(depth = 1)
	private CommonUser operator;
	
	/** 办理日期 */
	@Column
	@Field
	@Between
	private Date operateDate;
	
	/** 备注 */
	@Field
	@Column
	private String remark;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum TransferType {
		Transfer("转让"),
		Inherit("继承"), 
		Gift("赠与");

		private String display;
		TransferType(String display) {
			this.display = display;
		}
		public String getDisplay() {
			return display;
		}
	}

	public Long getPkCertificatesTransfer() {
		return pkCertificatesTransfer;
	}

	public void setPkCertificatesTransfer(Long pkCertificatesTransfer) {
		this.pkCertificatesTransfer = pkCertificatesTransfer;
	}

	public TravelContract getTravelContract() {
		return travelContract;
	}

	public void setTravelContract(TravelContract travelContract) {
		this.travelContract = travelContract;
	}

	public Member getAssignor() {
		return assignor;
	}

	public void setAssignor(Member assignor) {
		this.assignor = assignor;
	}

	public Member getReceiver() {
		return receiver;
	}

	public void setReceiver(Member receiver) {
		this.receiver = receiver;
	}

	public TransferType getTransferType() {
		return transferType;
	}

	public void setTransferType(TransferType transferType) {
		this.transferType = transferType;
	}

	public Double getWorkCost() {
		return workCost;
	}

	public void setWorkCost(Double workCost) {
		this.workCost = workCost;
	}

	public CommonUser getOperator() {
		return operator;
	}

	public void setOperator(CommonUser operator) {
		this.operator = operator;
	}

	public Date getOperateDate() {
		return operateDate;
	}

	public void setOperateDate(Date operateDate) {
		this.operateDate = operateDate;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	
}
